/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
#define Version002

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QUT.Bio.Util {
#if Version001
	/// <summary>
	/// A portable, if somewhat odd-looking, dialog box for showing text mssages to the user.
	/// </summary>
	
	public class Alert : PopupWindow {
		/// <summary>
		/// Creates a new Alert, but does not display it.
		/// </summary>
		/// <param name="format">A message format string of the kind used by String.Format().</param>
		/// <param name="items">Arguments to be displayed as part of the message.</param>
	
		public Alert ( string format, params object [] items ) {
			Grid buttonGrid = new Grid();

			buttonGrid.ColumnDefinitions.Add( new ColumnDefinition() {
				Width = new GridLength( 1, GridUnitType.Star )
			} );
			buttonGrid.ColumnDefinitions.Add( new ColumnDefinition() {
				Width = new GridLength( 1, GridUnitType.Auto )
			} );
			buttonGrid.ColumnDefinitions.Add( new ColumnDefinition() {
				Width = new GridLength( 1, GridUnitType.Star )
			} );

			Button okButton = new Button();
			okButton.Content = "Ok";
			okButton.Width = 50;
			okButton.SetValue( Grid.ColumnProperty, 1 );
			okButton.Margin = new Thickness( 0, 3, 0, 3 );
			okButton.Click += OkButtonClicked;
			buttonGrid.Children.Add( okButton );

			content.South = buttonGrid;
			
			content.Centre = new ScrollViewer {
				Content = new TextBlock{
					Text = string.Format( format, items )
				},
				 HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
				 VerticalScrollBarVisibility = ScrollBarVisibility.Auto
			};
			
			Width = 320;
			Height = 200;
			Left = 100;
			Top = 100;
		}

		private void OkButtonClicked ( object source, RoutedEventArgs args ) {
			base.OnCloseClicked( source, args );
		}
	}
#elif Version002
	/// <summary>
	/// Portable Messagebox.Show / Browser.Alert wrapper.
	/// </summary>

	public static class Alert {

		/// <summary>
		/// Displays an alert to the user.
		/// </summary>
		/// <param name="format">A format string that will control the appearance of the message.</param>
		/// <param name="arguments">Parameters for the message.</param>
		
		public static void Show ( string format, params object[] arguments ) {
			try {
#if SILVERLIGHT
			System.Windows.Browser.HtmlPage.Window.Alert( String.Format( format, arguments ) );
#else
			MessageBox.Show( string.Format( format, arguments ) );
#endif
			}
			catch ( Exception e ) {
				D.Bug( "Format exception:\n{0}", e );
			}
		}
	}
#endif
}
